package cn.itcast.hotel.listen;


import cn.itcast.hotel.service.IHotelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class HotelQueueListener {

    @Autowired
    IHotelService hotelService;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue("hotel.insert.queue"),
            exchange = @Exchange(value = "hotel.topic",type = ExchangeTypes.TOPIC),
            key = "hotel.insert"
    ))
    public void listenInserQueue(Long hotelId){
            log.info("接收到 新增索引消息 消息内容==》{}",hotelId);
            hotelService.insertById(hotelId);
    }
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue("hotel.delete.queue"),
            exchange = @Exchange(value = "hotel.topic",type = ExchangeTypes.TOPIC),
            key = "hotel.delete"
    ))
    public void listenDeleteQueue(Long hotelId){
        log.info("接收到 删除索引消息 消息内容==》{}",hotelId);
        hotelService.deleteById(hotelId);

    }



}
